package com.migu.contacts.util;

import com.github.heqiao2010.lunar.LunarCalendar;

import java.time.LocalDate;
import java.util.Calendar;

public class DateUtil {
    public static String getMothDay(LocalDate localDate) {
        String string = localDate.toString();
        return string.substring(5);
    }

    public static LocalDate solar2Lunar(LocalDate localDate) {
        Calendar instance = Calendar.getInstance();
        instance.set(localDate.getYear(), localDate.getMonthValue() - 1, localDate.getDayOfMonth());
        LunarCalendar lunar = LunarCalendar.solar2Lunar(instance);
        return LocalDate.of(lunar.getLyear(), lunar.getLmonth(), lunar.getLdate());
    }

    public static LocalDate lunar2Solar(LocalDate localDate) {
        LunarCalendar lunar = new LunarCalendar();
        Calendar today = LunarCalendar.lunar2Solar(localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth(), lunar.isLeapMonth());
        return LocalDate.of(today.get(Calendar.YEAR), today.get(Calendar.MONTH) + 1, today.get(Calendar.DAY_OF_MONTH));
    }
}
